package com.unisal.java;

import java.util.Iterator;

public class MenuJantarIterator implements Iterator<ItemDoMenu> {

	ItemDoMenu[] itens;
	Integer posicao = 0;

	public MenuJantarIterator(ItemDoMenu[] itens) {
		this.itens = itens;
	}

	@Override
	public boolean hasNext() {
		if (posicao >= itens.length || itens[posicao] == null) {
			return false;
		} else {
			return true;
		}
	}

	@Override
	public ItemDoMenu next() {
		ItemDoMenu itemDoMenu = itens[posicao];
		posicao += 1;
		return itemDoMenu;
	}

	@Override
	public void remove() {
		if (posicao <= 0)
			try {
				throw new IllegalAccessException("Nao pode remover o elemento");
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		if (itens[posicao - 1] != null) {
			for (Integer indice = posicao - 1; indice < (itens.length - 1); indice++) {
				itens[indice] = itens[indice + 1];
			}
			itens[itens.length - 1] = null;
		}
	}

}
